<?php
class UUserIdentity extends CUserIdentity {

    // username or password is incorect
    const ERROR_USERNAME_OR_PASSWORD=10;

    // user isn't activated
    const ERROR_INACTIVE=11;

    private $_id;

    public function authenticate() {

        $User = Users::model()->find('username="'.$this->username.'" AND password="'.UrbacHelper::hashWord($this->password).'"');
        if($User === null){
            $this->errorCode=self::ERROR_USERNAME_OR_PASSWORD;
        }
        else{
            if($User->active){
                $this->_id = $User->id;

                $this->errorCode = self::ERROR_NONE;
            }
            else{
                $this->errorCode = self::ERROR_INACTIVE;
            }
        }

        return !$this->errorCode;
    }

    public function getId()
    {
        return $this->_id;
    }


}

?>
